package design;

import java.io.IOException;
import java.util.StringTokenizer;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Mapper.Context;

public class Mapper2 extends Mapper
        <Object, Text, Text, Text> {
    private Text key_text = new Text();
    private Text value_text = new Text();

    public void map(Object key, Text value, Context context) throws IOException, InterruptedException {
        String line = value.toString();
        StringTokenizer itr = new StringTokenizer(line);
        int num = itr.countTokens() - 1;
        String no_attr = itr.nextToken();
        StringBuffer strbuffer = new StringBuffer();
        for (int i = 0; i < num; i++) {
            strbuffer.append(" " + itr.nextToken());
        }
        String str = strbuffer.toString();
        key_text.set(no_attr);//属性名作为key
        value_text.set(str);//属性值+label+记录数作为value
        context.write(key_text, value_text);
    }
}

